package com.example.canopytemperature;

import com.google.gson.Gson;

import java.util.Map;

import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;


public class OkHttpHelper {
    public  static  final String URL ="https://cbyhbsi.xyz/dataInterface";
    public  static  void  Post(String url , Map map , Callback callback){
        OkHttpClient client = new OkHttpClient();
        RequestBody body = RequestBody.create(MediaType.parse("application/json;UTF-8"),new Gson().toJson(map));
        Request request = new Request.Builder()
                .url(URL+url)
                .post(body)
                .build();
        client.newCall(request).enqueue(callback);
    }
    public  static  void  Get(String url,Callback callback){
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(URL+url)
                .get()
                .build();
        client.newCall(request).enqueue(callback);
    }
}
